package com.titan.core.utils.object;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.commons.collections4.OrderedMap;
import org.apache.commons.collections4.map.ListOrderedMap;

/**
 * @author 周成功
 * @email 86898837@qq.com
 * @date 2020年02月14日
 */
public class ListMap<K, V> implements java.io.Serializable, Cloneable {
    private static final long serialVersionUID = 1L;
    private ListOrderedMap<K, V> data = null; // new ListOrderedMap<K, V>();
    
    public <K,V> ListMap() {
        data = new ListOrderedMap();
    }
    public <K,V> ListMap(Map map) {
        data = ListOrderedMap.listOrderedMap(map);
    }
    public static <K,V> ListMap<K, V> $() {
        ConcurrentHashMap s;
        return new ListMap<K, V>();
    }
    public static <K,V> ListMap<K, V> $(int size) {
        ListMap<K,V> bean = new ListMap<K,V>(new HashMap<K,V>(size));
        return bean;
    }
    public static <K,V> ListMap<K, V> $(final Map<K, V> map) {
        return new ListMap<K, V>(map);
    }
    public static <K,V> ListMap<K, V> $Lock(int size) {
        ListMap<K,V> bean = new ListMap<K,V>(new ConcurrentHashMap<K,V>(size));
        return bean;
    }
    
    public ListMap<K,V> clone() {
        ListMap<K,V> dataNew = ListMap.$(data.size());
        for (int i = 0; i < data.size(); i++) {
            K key = data.get(i);
            V value = data.getValue(i);
            dataNew.put(key, value);
        }
        return dataNew;
    }
    
    public V put(final K key, final V value) {
        return data.put(key, value);
    }
    public V put(int index, final K key, final V value) {
        return data.put(index, key, value);
    }
    public void putAll(final Map<? extends K, ? extends V> map) {
        data.putAll(map);
    }

    
    public Set<K> keySet() {
        return data.keySet();
    }
    public List<K> keyList() {
        return data.keyList();
    }
    public List<V> valueList() {
        return data.valueList();
    }
    
    public K getKey(final int index) {
        return data.get(index);
    }
    public V getValue(final int index) {
        return data.getValue(index);
    }
    
    public V get(final K key) {
        return data.get(key);
    }

    public boolean containsKey(final K key) {
        return data.containsKey(key);
    }
    public boolean containsValue(final V value) {
        return data.containsValue(value);
    }
    
    public V removeKey(final K key) {
        return data.remove(key);
    }
    public V remove(final int index) {
        return data.remove(index);
    }    
    public void clear() {
        data.clear();
    }
    public int size() {
        return data.size();
    }
    
    public Map<K,V> toMap() {
        return data;
    }    
    public String toString() {
        return data.toString();
    }
    

}
